package net.itgoo.parkingpay.ui.recharge;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Map;

/**
 * Created by apple on 16/11/21.
 */
public class ParkingRechargePresenter implements ParkingRechargeContract.Presenter {

    private final ParkingRechargeContract.View mView;
    private final ParkingRechargeContract.DataSource mRepository;
    private Map<String, String> mParams;

    public ParkingRechargePresenter(Map<String, String> params, ParkingRechargeContract.View view,
                                    ParkingRechargeContract.DataSource repository) {
        mView = view;
        mRepository = repository;
        mParams = params;
        view.setPresenter(this);
    }

    @Override
    public void start() {

    }

    @Override
    public void stop() {
        mRepository.cancel();
    }

    @Override
    public void getData() {
        String plate = mParams.get("plate");
        mView.showPlate(plate);
    }

    @Override
    public void calculateAmount(int month) {
        double amount = month * 100;
        double total = amount + amount * 0.06;
        DecimalFormat f = new DecimalFormat("#####0.00");
        mView.showAmount(f.format(total));
    }
}
